﻿using System;
using System.Runtime.Serialization;

namespace Emico.Linq.Criterion
{
    [Serializable]
    public abstract class LogicalExpression<T> : AbstractExpression<T>
        where T : class
    {
        #region Variables

        #endregion

        #region Properties

        public IExpression<T> LHS
        {
            get;
            private set;
        }

        public IExpression<T> RHS
        {
            get;
            private set;
        }

        #endregion

        #region Constructors

        protected LogicalExpression(IExpression<T> lhs, IExpression<T> rhs)
        {
            if (lhs == null)
            {
                throw new ArgumentNullException("lhs");
            }

            if (rhs == null)
            {
                throw new ArgumentNullException("rhs");
            }

            this.LHS = lhs;
            this.RHS = rhs;
        }

        protected LogicalExpression(SerializationInfo info, StreamingContext context)
        {
            this.LHS = (IExpression<T>)info.GetValue("LHS", typeof(IExpression<T>));
            this.RHS = (IExpression<T>)info.GetValue("RHS", typeof(IExpression<T>));
        }

        #endregion

        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("LHS", this.LHS);
            info.AddValue("RHS", this.RHS);
        }
    }
}
